package rs.mbs2.epics.server.session.dao.bean;

import java.util.List;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.ejb.TransactionManagement;
import javax.ejb.TransactionManagementType;
import javax.persistence.Query;

import rs.mbs2.epics.server.entity.Album;
import rs.mbs2.epics.server.session.dao.localinterface.AlbumDaoLocal;

@Stateless
@Local(AlbumDaoLocal.class)
@TransactionManagement(TransactionManagementType.CONTAINER)
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public class AlbumDaoBean extends GenericDaoBean<Album, Integer> implements AlbumDaoLocal{

	@Override
	public List<Album> findAllAlbumsFromUser(Integer userId) {
		Query q = em.createNamedQuery("findAlbumsFromUser");		
		q.setParameter("userId", userId.toString());		
		
		@SuppressWarnings("unchecked")
		List<Album> res = q.getResultList();
		
		return res;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<Album> findAlbumsByPhotoId(Integer photoId) {
		
		Query q = em.createNamedQuery("findAlbumsByPhotoId");
		
		q.setParameter("photoId", photoId);
		
		return q.getResultList();
	}

}
